<?php

namespace App\Admin\Pages\General;

use App\Models\Config;
use Dcat\Admin\Form;
use Dcat\Admin\Widgets\Tab;
use Illuminate\Contracts\Support\Renderable;

class ConfigList implements Renderable
{
    public function render(): string
    {
        $model = new Config();
        $siteList = [];
        $groupList = Config::getGroupList();
        foreach ($groupList as $k => $v) {
            $siteList[$k]['name'] = $k;
            $siteList[$k]['title'] = $v;
            $siteList[$k]['list'] = [];
        }
        $tab = Tab::make();

//// 第一个参数是选项卡标题，第二个参数是内容，第三个参数是是否选中
//        $tab->add('选项卡1', view('...'), true);
//        $tab->add('选项2', 'html');
        foreach ($groupList as $k=>$v){
            $list = $model->where("group",$k)->get();
            foreach ($list as $key=>$value){

            }
            $form = Form::make($model, function (Form $form) {

            });
            $form->hasMany('paintings', function (Form\NestedForm $form) {

            })->useTable();
            $tab->add($v, '', $k=='basic');
        }
//        foreach ($model->all() as $k => $v) {
//            if (!isset($siteList[$v['group']])) {
//                continue;
//            }
//            $value = $v->toArray();
//            $value['title'] = __($value['title']);
//            if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) {
//                $value['value'] = explode(',', $value['value']);
//            }
//            $value['content'] = json_decode($value['content'], true);
////            if (in_array($value['name'], ['categorytype', 'configgroup', 'attachmentcategory'])) {
////                $dictValue = (array)json_decode($value['value'], true);
////                foreach ($dictValue as $index => &$item) {
////                    $item = __($item);
////                }
////                unset($item);
////                $value['value'] = json_encode($dictValue, JSON_UNESCAPED_UNICODE);
////            }
//            $value['tip'] = htmlspecialchars($value['tip']);
//            $siteList[$v['group']]['list'][] = $value;
//        }
//        $index = 0;
//        foreach ($siteList as $k => &$v) {
//            $v['active'] = !$index;
//            $index++;
//        }
//        $data = [
//            'siteList'=>$siteList,
//            'typeList'=>Config::getTypeList(),
//            'ruleList'=>Config::getRegexList(),
//            'groupList'=>Config::getGroupList()
//        ];


        return $tab->withCard();
    }
}
